package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Api(tags = "商家订单管理接口")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    // 商家订单管理接口
    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单条件查询")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = ordersService.conditionSerch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    //各个状态的订单数量统计
    @GetMapping("/statistics")
    @ApiOperation(value = "订单状态统计")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

    //订单详情
    @GetMapping("/details/{id}")
    @ApiOperation(value = "订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO orderVO = ordersService.details(id);
        return Result.success(orderVO);
    }

    //接单
    @PutMapping("/confirm")
    @ApiOperation(value = "接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        ordersService.confirm(ordersConfirmDTO.getId());
        return Result.success();
    }

    //拒单
    @PutMapping("/rejection")
    @ApiOperation(value = "拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    //取消订单
    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        ordersService.cancel(ordersCancelDTO);
        return Result.success();
    }

    //派送订单
    @PutMapping("/delivery/{id}")
    @ApiOperation(value = "派送订单")
    public Result delivery(@PathVariable Long id) {
        log.info("派送订单：{}", id);
        ordersService.delivery(id);
        return Result.success();
    }

    //完成订单
    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单")
    public Result complete(@PathVariable Long id) {
        log.info("完成订单：{}", id);
        ordersService.complete(id);
        return Result.success();
    }
}
